package com.wwz.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.io.Serializable;
import java.text.DecimalFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
@Data
@TableName("bs_user")
@NoArgsConstructor
@ApiModel("用户")
public class User implements Serializable {

    private static final long serialVersionUID = 4297464181093070302L;

    @Id
    @ApiModelProperty("主键id")
    private String id;

    @ApiModelProperty("手机号码")
    private String mobile;

    @ApiModelProperty("用户名称")
    private String username;

    @ApiModelProperty("密码")
    private String password;

    @ApiModelProperty("启用状态 0为禁用 1为启用")
    private Integer enableState;

    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty("创建时间")
    private Date createTime;

    @ApiModelProperty("企业id")
    private String companyId;

    @ApiModelProperty("企业名")
    private String companyName;

    @ApiModelProperty("部门ID")
    private String departmentId;

    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty("入职时间")
    private Date timeOfEntry;

    @ApiModelProperty("聘用形式")
    private Integer formOfEmployment;

    @ApiModelProperty("聘用形式name")
    @TableField(exist = false)
    private String formOfEmploymentValue;

    @ApiModelProperty("工号")
    private String workNumber;

    @ApiModelProperty("管理形式")
    private String formOfManagement;

    @ApiModelProperty("工作城市")
    private String workingCity;

    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty("转正时间")
    private Date correctionTime;

    @ApiModelProperty("在职状态 1.在职  2.离职")
    private Integer inServiceStatus;

    @ApiModelProperty("部门名称")
    private String departmentName;

    /**
     * level
     *     String
     *          saasAdmin：saas管理员具备所有权限
     *          coAdmin：企业管理（创建租户企业的时候添加）
     *          user：普通用户（需要分配角色）
     */
    @ApiModelProperty("等级")
    private String level;

    @ApiModelProperty("用户头像")
    private String staffPhoto;

    public User(Object [] values) {
        //用户名	手机号	工号	聘用 形式	入职 时间	部门编码
        this.username = values[1].toString();
        this.mobile = values[2].toString();
        this.workNumber = new DecimalFormat("#").format(values[3]);
        this.formOfEmployment =((Double) values[4]).intValue();
        this.timeOfEntry = (Date) values[5];
        this.departmentId = values[6].toString(); //部门编码 != 部门id
    }

    /**
     *  JsonIgnore
     *     : 忽略json转化
     */
    @JsonIgnore
    @ManyToMany
    @JoinTable(name="pe_user_role",joinColumns={@JoinColumn(name="user_id",referencedColumnName="id")},
            inverseJoinColumns={@JoinColumn(name="role_id",referencedColumnName="id")}
    )
    @TableField(exist = false)
    private Set<Role> roles = new HashSet<Role>();//用户与角色   多对多
}
